<template>
  <div class="wrapper">
    <div style="margin: 200px auto; background-color: #fff; width: 300px; padding: 20px; border-radius: 10px">
      <div style="margin: 20px 0;text-align: center; font-size: 24px"><b>选择您的餐桌号</b></div>
      <el-form :model="table" :rules="rules" ref="tableForm">
        <el-form-item prop="tableid">
          <el-input placeholder="餐桌号" size="medium" style="margin: 10px 0" prefix-icon="el-icon-user" v-model="table.tableid"></el-input>
        </el-form-item>

        <div style="margin: 10px 0;text-align: right">
          <el-button type="primary" size="small" autocomplete="off" @click="login">确定</el-button>
        </div>
      </el-form>
    </div>
  </div>
</template>

<script>
import request from "@/utils/request";
import ValidCode from "@/components/ValidCode.vue";

export default {
  name: "Table",
  data(){
    return{
      table:{},
      rules: {
        tableid: [
          { required: true, message: '请输入空闲餐桌号', trigger: 'blur' },
          { min: 1, max: 3, message: '长度在 1 到 3 个字符', trigger: 'blur' }
        ],
      },
    }
  },
  methods: {
    login(){
      this.$refs['tableForm'].validate((valid) => {
        if (valid) {
          localStorage.setItem("tableid",JSON.stringify(this.table.tableid));
          this.$message.success("欢迎使用'智慧食堂'! ")
          this.$router.push("/pork");
        } else {
          this.$message.error("餐桌号不可为空！");
          return false;
        }
      })
    }
  },
}
</script>

<style scoped>
.wrapper {
  height: 100vh;
  background-image: linear-gradient(to bottom right, #FC466B, #3F5EFB);
  overflow: hidden;
}
</style>